<template>
  <el-form ref="postForm_examine" :model="postForm_examine" :rules="rules">
    <sticky :class-name="'sub-navbar'" v-show="!adminshow">
      <el-button v-if="!isEdit" @click="showGuide">显示帮助</el-button>
      <el-button
        v-loading="loading"
        type="success"
        style="margin-left: 10px"
        @click="submitForm"
      >
        {{ isEdit ? '审核报名表' : '新增报名表' }}
      </el-button>
    </sticky>
    <div class="detail-container">
      <el-row>        
        <el-col :span="24">    
          <el-form-item prop="examine_status" label="审核状态：" :label-width="labelWidth" v-show="!adminshow">
            <el-select v-model="postForm_examine.examine_status" placeholder="请选择" clearable>
                <el-option
                  v-for="item in examine_options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </el-form-item> 
          <el-form-item prop="examine_explain" label="审核说明：" :label-width="labelWidth" v-show="!adminshow">
            <el-input
              type="textarea"
              :rows="3"
              placeholder="请输入审核说明"
              v-model="postForm_examine.examine_explain">
            >
            </el-input>
          </el-form-item> 
        </el-col>
      </el-row> 
      <el-row>
        <div class="block">
          <el-timeline>
            <el-timeline-item v-for="(activity, index) in listExamine" :key="index" :timestamp="activity.examine_time | timeFilter" placement="top" >
              <el-card>
                <h4>{{activity.examine_explain}}</h4>
                <p>{{activity.examine_operator}} 提交于 {{activity.examine_status}}</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </div>
      </el-row>   
    </div>
    <el-col :span="24">
      <el-row type="flex" justify="center">
        <el-col :span="24"><div style="color:#000;font-size:25px;line-height:60px;text-align:center;">德宏师范高等专科学校2023年公开招聘工作人员报名登记表</div></el-col>
      </el-row>
      <table border="1px" cellpadding="0px" cellspacing="0px" style="width:89%;margin:10px auto">
        <tr>
          <td style="width:10%;" class="biankuang">报考单位</td>
          <td style="width:35%;" class="biankuang" colspan="3">德宏师范高等专科学校</td>
          <td style="width:15%;" class="biankuang">主管部门</td>
          <td style="width:40%;" class="biankuang" colspan="2">云南省教育厅</td>
        </tr>
        <tr>
          <td class="biankuang">报考岗位</td>
          <td  class="biankuang" colspan="3">{{postForm.post}}</td>
          <td class="biankuang">岗位代码</td>
          <td class="biankuang">{{postForm.post_code}}</td>
          <td class="biankuang" rowspan="7" style="width:20%;">照片</td>
        </tr>
        <tr>
          <td class="biankuang">姓名</td>
          <td style="width:12%;" class="biankuang">{{postForm.enroll_name}}</td>
          <td class="biankuang">性别</td>
          <td class="biankuang">{{this.postForm.sex}}</td>
          <td class="biankuang">出生年月</td>
          <td class="biankuang">{{this.postForm.date_of_birth}}</td>
        </tr>
        <tr>
          <td class="biankuang">民族</td>
          <td class="biankuang">{{postForm.ethnic}}</td>
          <td class="biankuang" colspan="2">政治面貌</td>
          <td class="biankuang" colspan="2">{{this.postForm.politics_status}}</td>
        </tr>
        <tr>
          <td class="biankuang">学历</td>
          <td class="biankuang">{{this.postForm.education_background}}</td>
          <td class="biankuang" colspan="2">学位</td>
          <td class="biankuang" colspan="2">{{this.postForm.degree}}</td>
        </tr>
        <tr>
          <td class="biankuang">专业技术职称</td>
          <td class="biankuang">{{this.postForm.zhicheng}}</td>
          <td class="biankuang" colspan="2">专业技术职称级别</td>
          <td class="biankuang" colspan="2">{{this.postForm.zhichengjibie}}</td>
        </tr>
        <tr>
          <td class="biankuang" colspan="2">毕业学校及时间</td>
          <td class="biankuang" colspan="4">{{this.postForm.school_and_date_of_graduation}}{{this.postForm.graduation_time}}</td>      
        </tr>
        <tr>
          <td class="biankuang" colspan="2">所学专业</td>
          <td class="biankuang" colspan="4">{{this.postForm.what_specific}}</td>      
        </tr>
        <tr>
          <td class="biankuang" colspan="2">专业方向</td>
          <td class="biankuang" colspan="5">{{this.postForm.main_specialties}}</td>      
        </tr>
        <tr >
          <td class="biankuang" colspan="2">现工作单位</td>
          <td class="biankuang" colspan="5">{{this.postForm.resume}}</td>      
        </tr>
        
        <tr>
          <td class="biankuang" colspan="2">身份证号码</td>
          <td class="biankuang" colspan="5">{{this.postForm.ID_card_No}}</td>      
        </tr>
        <tr style="height:300px">
          <td class="biankuang" colspan="2">现研究方向及主要成果</td>
          <td class="biankuang" colspan="5">{{this.postForm.achievement}}</td>      
        </tr>
        
        <tr>
          <td class="biankuang" colspan="2">联系电话</td>
          <td class="biankuang" colspan="5">{{this.postForm.contact_way}}</td>      
        </tr>
        <tr>
          <td class="biankuang" >证明材料</td>
          <td class="biankuang" colspan="6" style="padding-top:20px">
            <el-row :span="16" v-for="(o, index) in fileList" :key="index">
              <el-card :body-style="{ padding: '0px' }">
                <img :src="o.url" class="image">
                <div style="padding: 14px;">
                  <span>{{o.name}}</span>
                </div>
              </el-card>
            </el-row>
          </td>      
        </tr>
      </table>
    </el-col>
  </el-form>
</template>

<script>
// eslint-disable-next-line
/* eslint-disable */
import Cookies from 'js-cookie'
import { mapGetters } from 'vuex'
import Sticky from '../../../components/Sticky'
import Warning from './Warning'
import { listExamineEnroll, updateEnroll1, getOneEnroll ,createEnrollExamine } from '../../../api/enroll'
//import MarkdownEditor from '@/components/MarkdownEditor'
import { parseTime } from '../../../utils'
const fields = {
  
}
export default {
  components: { Sticky, Warning },
  filters: {
    valueFilter(value) {
      return value || '无'
    },
    timeFilter(time) {
      return time ? parseTime(time, '{y}-{m}-{d} {h}:{i}') : '无'
    }
  },
  props: {
    isEdit: Boolean
  },
  data() {
    const validateRequire = (rule, value, callback) => {
      if (value.length === 0) {
        callback(new Error(fields[rule.field] + '必须填写'))
      } else {
        callback()
      }
    }
    return {
      loading: false,
      postForm_examine: {examine_status:'', examine_name:'',examine_operator:'',examine_time:''},
      postForm:{},
      fileList: [],
      fileList_enroll:[],
      listQuery: {},
      arr:[],
      userInfo: {},
      labelWidth: '120px',
      categoryList:[],
      date_of_birth:'',
      baoming:'',
      adminshow:false,
      listbaoming:[],
      listExamine:[],
      listQuery:{},
      rules: {
        examine_explain: [{ required: true, message: '请输入审核说明', trigger: 'blur' }],
        examine_status: [{required: true, message: '请选择审核状态', trigger: 'change'}],
      },
      examine_options:[
        {
          value: '审核不通过',
          label: '审核不通过'
        }, 
        {
          value: '初审通过',
          label: '初审通过'
        }]
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
        if (this.isEdit) {
          //判断是否是admin用户
          let usernameinfo=Cookies.get('username')
          if(usernameinfo!='admin'){
              this.adminshow=true
            }
          const fileName = this.$route.params.fileName
          
          //
          
          getOneEnroll(fileName).then(response => {
            //console.log(response)
            this.postForm=response.data
            this.postForm_examine.examine_status=response.data.enroll_status
            this.arr = JSON.parse(response.data.enroll_img)
            this.listQuery.enroll_adminuser=response.data.enroll_adminuser
            //获取报名状态列表
            listExamineEnroll(this.listQuery).then(response => {
            //console.log(response)
            this.listExamine=response.data
            //this.postForm_examine.examine_status=response.data.enroll_status
            //this.arr = JSON.parse(response.data.enroll_img)
            //console.log(this.arr1)
            }
            ).catch(() => {
              this.loading = false
            })
            //console.log(this.arr1)
        this.arr.forEach((item)=>{
          //console.log(item.name)
            this.fileList.push({name: item.name, url: item.url})
            //console.log(this.fileList)
        })

      }
   ).catch(() => {
        this.loading = false
      })
      console.log(fileName)
    }
    //this.getCategoryList()
      
      //}
  },
  methods: {
    onContentClick(data) {
      //console.log(data)
      if (data.text) {
        window.open(data.text)
      }
    },
    setDefault() {
      // this.postForm = Object.assign({}, defaultForm)
      this.$router.go(-1)
      //this.postForm={state:"1"}
    },
    
    onsuccess(res){
       this.$notify({
          title: '上传资料图片成功',
          message: '上传资料图片成功',
          type: 'success',
          duration: 2000
        })     
    },
    submitForm() {
      const onSuccess = (response) => {
        const { msg } = response
        this.$notify({
          title: '操作成功',
          message: msg,
          type: 'success',
          duration: 2000
        })
        this.loading = false
      }

      if (!this.loading) {
        this.loading = true
        //this.postForm.enroll_status="已提交"
        
        this.$refs.postForm_examine.validate((valid, fields) => {
          console.log(valid, fields)
          if (valid) {
            let usernameinfo=Cookies.get('username')
            this.postForm.enroll_status=this.postForm_examine.examine_status
            this.postForm_examine.examine_operator=usernameinfo
            this.postForm_examine.examine_name=this.postForm.enroll_adminuser
            const enroll = Object.assign({}, this.postForm)
            const enroll_examine=Object.assign({}, this.postForm_examine)
            //console.log(enroll)
            
              updateEnroll1(enroll).then(response => {
                onSuccess(response)
                createEnrollExamine(enroll_examine).then(responsel => {
                  onSuccess(responsel)
                  this.setDefault()
                }).catch(() => {
                  this.loading = false
                })
              }).catch(() => {
                this.loading = false
              })
            
          } else {
            const message = fields[Object.keys(fields)[0]][0].message
            this.$message({ message, type: 'error' })
            this.loading = false
          }
        })
      }
    },
    showGuide() {
      console.log('show guide...')
    }
  }
}
</script>

<style lang="scss" scoped>
  .detail-container {
    padding: 40px 50px 20px;
    .preview-img {
      width: 200px;
      height: 270px;
    }
  }
  .image {
    width: 100%;
    height:100%;
    display: block;
  }
  .biankuang {
    //border: 1px solid #000;
    color:#000;
    font-size: 16px;
    line-height: 40px;
    text-align: center;
  }
</style>
